/**
 * 软件下载的JS方法
 */
XF.Faq = new function(){
	this.init = function(){

	};
	
	this.init_css = function(){
	    $(".oaTable table.tableList tbody tr:not('#tableHeader')").hover(
            function () {
                $(this).addClass("hover");
            }, function () {
                $(this).removeClass("hover");
            }
        );
	};
	
	this.listFaq = function(){
		XF.lightSideBar('listFaq');
		$.ajax({
			type:'post',
			url:global.contextPath + "/faq/faql",
			complete:function(xhr){
				xhr = xhr['responseText'];
				$('#faqCenter').html(xhr);
			}
		});	
	};
	
	this.manageFaq = function(){
		XF.lightSideBar('manageFaq');
		_search_listFaq(null, null, null, null, null, null);
	};
	
	this.addFaq = function(faqClass,linkman){
		XF.lightSideBar(linkman);
		$.ajax({
			type:'post',
			data:{faqClass:faqClass},
			url:global.contextPath + "/faq/add",
			complete:function(xhr){
				xhr = xhr['responseText'];
				$('#faqCenter').html(xhr);
			}
		});
	};

	this.editFaq = function(faqId){
		$.ajax({
			type:'post',
			url:global.contextPath + "/faq/edit",
			data:{faqId:faqId},
			complete:function(xhr){
				xhr = xhr['responseText'];
				$('#faqCenter').html(xhr);
			}
		});
	};

	/**
	 * 添加失败错误提示
	 */
	this.refreshAfterAddFaild = function(errorJson){
		if(typeof(errorJson)=="undefined")return;
		if(errorJson==null || errorJson=="")return;
		for(key in errorJson){
			var v = errorJson[key];
			var errorTip = $("#errorTip_"+key);
			errorTip.html(v);
			errorTip.show();
		}
	};	
	
	this.detail = function(id){
		var url  = global.contextPath + "/faq/detail"
		$.ajax({
		  url: url,
		  type: "post",
		  data: {faqId:id},
		  complete: function(xhr){
			  xhr = xhr['responseText'];
			  $("#faqCenter").html(xhr);
		  }
		});
	};
		
	
	this.deleteFaq = function(faqId){
		$.messager.confirm('提示','确认删除这条FAQ吗?',function(r){
			if(r){
				var url = global.contextPath + "/faq/deleteFaq";
				$.ajax({
					url:url,
					type:"post",
					data:{faqId:faqId},
					complete:function(xhr){
						xhr = xhr['responseText'];
						xhr = new Function('return' + xhr);
						xhr = xhr();
						xhr = xhr['status'];
						if(xhr=="SUCCESS"){
							$.messager.show({
								title:'提示',
								msg:'删除成功',
								timeout:3000,
								showType:'slide'
							});
							//$("#faqListWrap tr i[s="+faqId+"]").parent().parent().parent().remove();
							_search_listFaq(null, null, null, null, null, null);
						}else if(xhr=="FAILD"){
							$.messager.show({
								title:'提示',
								msg:'删除失败',
								timeout:3000,
								showType:'slide'
							});
						}
					}
				});
			}
		});
	};
	
	
    this.searchFaq = function(faqClass){
    	_search('','',faqClass);
    };
    
    this.searchByFaqClass = function(faqClass){
    	_search('','',faqClass);
    	XF.Faq.searchByGroupAfterHanlder(faqClass);
    };
    
    this.searchByGroupAfterHanlder = function(faqClass){
    	var groups = $("#faqTab li");
    	var targetGroup = $("#faqTab li[value='"+faqClass+"']");
    	groups.removeClass("focus");
    	targetGroup.addClass("focus");
    };

    this.listFaqSearch = function(orderByFields){
    	var orderByField = null;
    	var orderByMode = null;
		if(typeof(orderByFields)!="undefined"){
			orderByField = orderByFields;
		}
    	var td = $("th[orderByField="+orderByField+"]");
    	var orderByMode = td.find("span.px").attr("orderByMode");
    	
		var faqQuestion = $("input[name=faqQuestion]").val();
		var publicMan = $("input[name=publicMan]").val();
		var faqClass = $("select[name=faqClass]").val();
		var createDateBegin =  $('#createDateBegin').datebox('getValue');
		var createDateEnd =  $('#createDateEnd').datebox('getValue');
		_search_listFaq(orderByField,orderByMode,faqQuestion,faqClass,publicMan,createDateBegin,createDateEnd);
    	
    };
    
    function _search_listFaq(orderByField,orderByMode,faqQuestion,faqClass,publicMan,createDateBegin,createDateEnd){
    	config.listFaq_search['args']=[orderByField,orderByMode,faqQuestion,faqClass,publicMan,createDateBegin,createDateEnd];
    	SMT.xconfig.gvar.pageNum = '1';
    	SMT.ajax(config.listFaq_search);   	
    };
    
    

    function _search(orderByField,orderByMode,faqClass){
    	config.faq_search['args'] = [orderByField,orderByMode,faqClass];
    	SMT.xconfig.gvar.pageNum = '1';
    	SMT.ajax(config.faq_search);
    }
}();

config.faq_search = {
	url: ""+global.contextPath+"/faq/list",
    argsOrder: ['orderByField','orderByMode','faqClass'],
    needVar: true,
    replaceExp: '#replaceDiv',
    callBack: function() {
    }		
};

config.listFaq_search = {
		url: ""+global.contextPath+"/faq/manageFaqList",
	    argsOrder: ['orderByField','orderByMode','faqQuestion','faqClass','publicMan','createDateBegin','createDateEnd'],
	    needVar: true,
	    replaceExp: '#faqCenter',
	    callBack: function() {
	    }
};
